package com.pack;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * author: cjianquan
 * date: 2016/9/2
 */
@Controller
@RequestMapping("/packController")
public class PackController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private PackService packService;


    @RequestMapping(value = "/goPack")
    public String goPack(HttpServletRequest request){
        return "pack";
    }

    @RequestMapping(value = "/getUpdatefiles")
    @ResponseBody
    public List<String> getUpdatefiles(PackBean packBean, HttpServletRequest request){
        List<String> fileList = new ArrayList<String>();

        try{
            fileList = this.packService.getUpdatefiles(packBean);
        }catch (Exception e){
            logger.error(e.getMessage(),e);
        }
        logger.info(fileList.toString());
        return fileList;
    }

    @RequestMapping(value = "/packFiles")
    @ResponseBody
    public String packFiles(HttpServletRequest request,PackBean packBean){
        String msg = "";
        //1.源码备份，目前这一步先省略
        //2.编译文件拷贝

        try {
            this.packService.packFiles(packBean);
            msg = "success";
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            msg = "fail";
        }

        return msg;
    }

}

